package com.dp.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dp.common.annotation.Log;
import com.dp.common.core.controller.BaseController;
import com.dp.common.core.domain.AjaxResult;
import com.dp.common.enums.BusinessType;
import com.dp.system.domain.SysAlarmLog;
import com.dp.system.service.ISysAlarmLogService;
import com.dp.common.utils.poi.ExcelUtil;
import com.dp.common.core.page.TableDataInfo;

/**
 * 报警记录Controller
 *
 * @author ruoyi
 * @date 2025-02-10
 */
@RestController
@RequestMapping("/system/log")
public class SysAlarmLogController extends BaseController
{
    @Autowired
    private ISysAlarmLogService sysAlarmLogService;

    /**
     * 获取当前的温度报警信息
     * @return 温度报警信息列表
     */
    @GetMapping("/current")
    public AjaxResult getCurrentAlarmLogs() {
        List<SysAlarmLog> alarmLogs = sysAlarmLogService.getCurrentAlarmLogs();
        System.out.println("返回的报警信息数据：" + alarmLogs);
        return AjaxResult.success(alarmLogs);
    }
    /**
     * 查询报警记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAlarmLog sysAlarmLog)
    {
        startPage();
        List<SysAlarmLog> list = sysAlarmLogService.selectSysAlarmLogList(sysAlarmLog);
        return getDataTable(list);
    }

    /**
     * 导出报警记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:export')")
    @Log(title = "报警记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAlarmLog sysAlarmLog)
    {
        List<SysAlarmLog> list = sysAlarmLogService.selectSysAlarmLogList(sysAlarmLog);
        ExcelUtil<SysAlarmLog> util = new ExcelUtil<SysAlarmLog>(SysAlarmLog.class);
        util.exportExcel(response, list, "报警记录数据");
    }

    /**
     * 获取报警记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:log:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return success(sysAlarmLogService.selectSysAlarmLogByLogId(logId));
    }

    /**
     * 新增报警记录
     */
    @PreAuthorize("@ss.hasPermi('system:log:add')")
    @Log(title = "报警记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAlarmLog sysAlarmLog)
    {
        return toAjax(sysAlarmLogService.insertSysAlarmLog(sysAlarmLog));
    }

    /**
     * 修改报警记录
     */
    @PreAuthorize("@ss.hasPermi('system:log:edit')")
    @Log(title = "报警记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAlarmLog sysAlarmLog)
    {
        return toAjax(sysAlarmLogService.updateSysAlarmLog(sysAlarmLog));
    }

    /**
     * 删除报警记录
     */
    @PreAuthorize("@ss.hasPermi('system:log:remove')")
    @Log(title = "报警记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(sysAlarmLogService.deleteSysAlarmLogByLogIds(logIds));
    }

    /**
     * 获取报警记录统计数据，用于绘制报警记录图形
     */
    @GetMapping("/alarmStatistics")
    public AjaxResult getAlarmStatistics() {
        List<Object> data = sysAlarmLogService.getAlarmStatistics();
        return success(data);
    }

}